a11y: Fix accessible tree inconsistency
authorMatthias Clasen <mclasen@redhat.com>
Tue, 20 Oct 2020 01:13:27 +0000 (21:13 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 20 Oct 2020 01:15:44 +0000 (21:15 -0400)
The stack page objects were not properly integrated
in the accessible tree - they were appearing as parent
of the pages when navigating up, but not as children
of the stack when navigating down.

gtk/a11y/gtkatspicontext.c

index 9c801bf0f3b2127659cb5102ef3e166b55517b37..a72a6ad40eed95ce375c28693832b71210d196a4 100644 (file)
@@ -455,15 +455,31 @@ handle_accessible_method (GDBusConnection       *connection,
     }
   else if (g_strcmp0 (method_name, "GetChildAtIndex") == 0)
     {
-      GtkWidget *child = NULL;
+      GtkATContext *context = NULL;
+      GtkAccessible *accessible;
       int idx, real_idx = 0;
+      const char *name;
+      const char *path;
 
       g_variant_get (parameters, "(i)", &idx);
 
-      GtkAccessible *accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
-      if (GTK_IS_WIDGET (accessible))
+      accessible = gtk_at_context_get_accessible (GTK_AT_CONTEXT (self));
+
+      if (GTK_IS_STACK_PAGE (accessible))
+        {
+          if (idx == 0)
+            {
+              GtkWidget *child;
+
+              child = gtk_stack_page_get_child (GTK_STACK_PAGE (accessible));
+              if (gtk_accessible_should_present (GTK_ACCESSIBLE (child)))
+                context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (child));
+            }
+        }
+      else if (GTK_IS_WIDGET (accessible))
         {
           GtkWidget *widget = GTK_WIDGET (accessible);
+          GtkWidget *child;
 
           real_idx = 0;
           for (child = gtk_widget_get_first_child (widget);
@@ -478,18 +494,17 @@ handle_accessible_method (GDBusConnection       *connection,
 
               real_idx += 1;
             }
-        }
-      else if (GTK_IS_STACK_PAGE (accessible))
-        {
-          if (idx == 0)
+
+          if (child)
             {
-              child = gtk_stack_page_get_child (GTK_STACK_PAGE (accessible));
-              if (!gtk_accessible_should_present (GTK_ACCESSIBLE (child)))
-                child = NULL;
+              if (GTK_IS_STACK (accessible))
+                context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (gtk_stack_get_page (GTK_STACK (accessible), child)));
+              else
+                context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (child));
             }
         }
 
-      if (child == NULL)
+      if (context == NULL)
         {
           g_dbus_method_invocation_return_error (invocation,
                                                  G_IO_ERROR,
@@ -498,10 +513,8 @@ handle_accessible_method (GDBusConnection       *connection,
           return;
         }
 
-      GtkATContext *context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (child));
-
-      const char *name = g_dbus_connection_get_unique_name (self->connection);
-      const char *path = gtk_at_spi_context_get_context_path (GTK_AT_SPI_CONTEXT (context));
+      name = g_dbus_connection_get_unique_name (self->connection);
+      path = gtk_at_spi_context_get_context_path (GTK_AT_SPI_CONTEXT (context));
 
       g_dbus_method_invocation_return_value (invocation, g_variant_new ("((so))", name, path));
     }